package sr.codemg.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sr.codemg.entity.SysUsers;
import sr.codemg.mapper.SysUsersMapper;
import sr.codemg.service.SysUsersService;
import sr.codemg.utils.Constants;
import sr.codemg.utils.ResponseCode;
import sr.codemg.utils.StaticFunc;
import sr.codemg.vm.Base;
import sr.codemg.vm.Selects;
import sr.codemg.vm.Tables;

import java.util.List;
import java.util.Map;

/**
 * 用户信息
 **/
@Service
public class SysUsersServiceImpl implements SysUsersService {

    @Autowired
    SysUsersMapper sysUsersMapper;

    @Override
    public SysUsers get(String id) {
        return sysUsersMapper.get(id);
    }

    @Override
    public Tables findList(Map<String, Object> params) {
        StaticFunc.page(params);
        List<SysUsers> data = sysUsersMapper.findList(params);
        Integer count = sysUsersMapper.count(params);
        return new Tables(data, count);
    }

    @Override
    public Base.Response add(SysUsers entity) {
        sysUsersMapper.add(entity);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Base.Response update(SysUsers entity) {
        sysUsersMapper.update(entity);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Base.Response delete(String id) {
        sysUsersMapper.delete(id);
        return ResponseCode.getBase(Constants.SUCC);
    }

    @Override
    public Selects.Response select(Selects.Request req) {
        req.configPage();
        List<Selects.Select> data = sysUsersMapper.select(req);
        Selects.Response res = new Selects.Response();
        res.setData(data);
        return res;
    }

    @Override
    public Base.Response reset(String account) {
        SysUsers user = get(account);
        user.setPass("C7F66BEEE198FB411C8623E53CBBC6EB1E0F078B5D68ED7F10D02FFB0AF46D44");
        sysUsersMapper.update(user);
        return ResponseCode.getBase(Constants.SUCC);
    }
}

